1 //------------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // Implements the interface to the application manifest
9 // 2005/05/09 - [....] Created
10 // 2007/09/20 [....] Ported Windows->DevDiv. See SourcesHistory.txt.
12 //------------------------------------------------------------------------
14 #include "PreCompiled.hxx"
15 #include "MarkupVersion.hxx"
16 #include "..\inc\registry.hxx"
19 #define COMPATURL L"http://schemas.openxmlformats.org/markup-compatibility/2006"
20 #define COMPATURL_LENGTH 63
22 #define IGNORABLE L"Ignorable"
23 #define IGNORABLE_LENGTH 9
25 #define MAX_PREFIX_LENGTH 128
27 CMarkupVersion::CMarkupVersion(__in LPCWSTR pswzLocalMarkupPath
)
29 SetLocalMarkupPath(pswzLocalMarkupPath
);
33 STDMETHODIMP
CMarkupVersion::QueryInterface(const struct _GUID
&riid
,void ** ppvObject
)
37 if (riid
== IID_IUnknown
)
39 *ppvObject
= static_cast<ISAXContentHandler
*>(this);
41 else if (riid
== __uuidof(ISAXContentHandler
))
43 *ppvObject
= static_cast<ISAXContentHandler
*>(this);
57 STDMETHODIMP_(DWORD
) CMarkupVersion::AddRef()
59 return InterlockedIncrement(&m_refCount
);
62 STDMETHODIMP_(DWORD
) CMarkupVersion::Release()
64 InterlockedDecrement(&m_refCount
);
76 IFACEMETHODIMP
CMarkupVersion::startPrefixMapping(
77 __in
const wchar_t* pwchPrefix
,
78 __in
int /*cchPrefix*/,
79 __in
const wchar_t* pwchUri
,
84 // Accumulate and record the namespaces
86 // See if it is a namespace that we know.
87 CString
* strVersion
= NULL
;
88 if (SUCCEEDED(m_mapNamespaceVersion
.Find(pwchUri
, &strVersion
)))
90 CString
*pUriString
= CString::CreateOnHeap(pwchUri
);
92 CKHR(m_mapPrefixNamespace
.Add(pwchPrefix
, pUriString
));
99 IFACEMETHODIMP
CMarkupVersion::startElement(
100 __in_ecount(cchNamespaceUri
) const wchar_t *pwchNamespaceUri
,
101 __in
int cchNamespaceUri
,
102 __in_ecount(cchLocalName
) const wchar_t *pwchLocalName
,
103 __in
int cchLocalName
,
104 __in_ecount(cchQName
) const wchar_t *pwchQName
,
106 __in ISAXAttributes
*pAttributes
)
110 const UINT BUFFER_LENGTH
= 1024;
113 // This retrieves a space-delimited list of the ignorable prefices.
114 // If there is some error finding the attribute, or if it wasn't there, we don't care.
115 // Returning a failed HRESULT will stop the parsing. The namespaces have already been
116 // reported in startPrefixMapping.
117 int nLength
= BUFFER_LENGTH
;
118 CKHR(pAttributes
->getValueFromName(COMPATURL
, COMPATURL_LENGTH
, IGNORABLE
, IGNORABLE_LENGTH
, &pwzValue
, &nLength
));
120 WCHAR wzPrefix
[MAX_PREFIX_LENGTH
];
121 LPCWSTR pStart
= pwzValue
;
124 // Remove any leading spaces
125 while (*pStart
&& *pStart
== L
' ')
130 // Get the prefix from the space-delimited list
131 __bound UINT nIndex
= 0;
132 while (*pStart
&& *pStart
!= L
' ' && nIndex
< MAX_PREFIX_LENGTH
- 1)
134 wzPrefix
[nIndex
++] = *(pStart
++);
136 wzPrefix
[nIndex
] = 0;
140 CString
* pStrNamespace
= NULL
;
141 if (SUCCEEDED(m_mapPrefixNamespace
.Find(wzPrefix
, &pStrNamespace
)))
143 // This is a namespace we know about
144 CString
* pStrVersion
= NULL
;
145 if (SUCCEEDED(m_mapNamespaceVersion
.Find(pStrNamespace
->GetValue(), &pStrVersion
)))
147 CKHR(m_mapIgnorableNamespaceVersion
.Add(pStrNamespace
->GetValue(), pStrVersion
));
153 CKHR(E_FAIL
); // to stop the parsing
159 HRESULT
CMarkupVersion::Read()
162 ISAXXMLReader
* pReader
= NULL
;
164 EventWriteWpfHostUm_ParsingMarkupVersionStart();
166 CKHR(GetStringMapFromRegistry(HKEY_LOCAL_MACHINE
, RegKey_WPF_Namespaces
, m_mapNamespaceVersion
));
168 if (m_mapNamespaceVersion
.GetCount() > 0)
170 CKHR(CoCreateInstance(__uuidof(SAXXMLReader
), NULL
, CLSCTX_INPROC_SERVER
, __uuidof(ISAXXMLReader
), (void**)&pReader
));
171 CKHR(pReader
->putContentHandler(this));
172 hr
= pReader
->parseURL(GetLocalMarkupPath());
174 // If we stopped the parse because we found the version, hr will be E_FAIL and
175 // the version will be set in the manifest.
182 EventWriteWpfHostUm_ParsingMarkupVersionEnd();
185 SAFERELEASE_POINTER(pReader
);